<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
  <head>
    <title>[${username}]-控制台</title>
	<meta name="content-type" content="text/html; charset=gbk">
	<link rel="stylesheet" type="text/css" href="css/sweetalert.css">
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/sweetalert.min.js"></script> 
		<script>
		$(document).ready(function()
		{
			if(getLoginStatus() == true)
				{
				getLoginInfo();
				getGroupName();
				}
		}
		);
		
		function getLoginStatus(success_function,fail_function)
		{
			var bol=false;
			$.ajax({
		        type:'post',
		        async:false,
		        url:'${pageContext.request.contextPath}/getLoginStatus',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            if(data['status'] == "false")
		            {
		            	swal({ 
							  title: "Error!", 
							  text: "请先登陆!",
							  type: "error", 
							  confirmButtonText: "Go >>",
							  closeOnConfirm: false, 
							  showLoaderOnConfirm: true 
							},
							function(){ 
							    window.location.href = "signIn";
							});
					}
					else
					{
					bol = true;
					}
		            }});
		            return bol;
		}
		
		function getLoginInfo()
		{
			$.ajax({
		        type:'post',
		        url:'${pageContext.request.contextPath}/getLoginInfo',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            $('#userInfo').html("username:"+data['username']+"<br \>createtime:"+
		            data['createtime']+"<br \> groupid:"+data['groupid']);
		            }});
		}
		
		function getGroupName()
		{
		$.ajax({
		        type:'post',
		        url:'${pageContext.request.contextPath}/getGroupName',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            $('#userInfo').append("<br \>groupname:"+data['msg']+"<br>");
		            }});
		}
		
		function signOut()
		{
		swal({ 
			title: "注销提示？", 
			text: "有些信息需要登录以后才能查阅！", 
			type: "warning",
			showCancelButton: true, 
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确认！", 
			closeOnConfirm: false
			},
			function(){
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/signOut',
				contentType:'application/json;charset=utf-8',//指定为json类型
				success:function(data){//返回json结果
				//
					if(data['status']=="success")
					{
					swal("成功！", "你的登录已被注销。", "success");
					window.location.href="home"; 
					}
					else if(data['status']=="fail")
					{
					swal("失败！", "未查询到登录信息。", "error");
					window.location.href="home";
					}
				//
				}});
		});
		}
		
		</script>
  </head>
  
  <body>
  <span id="userInfo"></span>
  
  <h4><a href="home">home</a>--<a style="color:#DD6B55;" href="javascript:signOut()">注销</a>会话</h4>
  <h3><a href="roleTable">用户&角色查看</a></h3>
  <hr> 
  </body>
</html>
